package com.nobrain.uboard.observer;

import java.util.ArrayList;


public class ObserverManager implements IObserverManager{
	private ArrayList<IObserver> observers;
	private static ObserverManager mObserverManager;
	private int observerSize;
	
	public final static int TYPE_MAIN_SERVICES = 0;
	
	public static ObserverManager getInstance(){
		if(mObserverManager == null){
			mObserverManager = new ObserverManager();
			mObserverManager.observers = new ArrayList<IObserver>();
			mObserverManager.observerSize = 0;
		}
		return mObserverManager;
	}

	@Override
	public void notifyObservers(int type) {
		for(int i=observerSize-1;i>0;i--){
			observers.get(i).update(type);
		}
	}

	@Override
	public void addObserver(IObserver o) {
		observers.add(o);
		observerSize++;
	}

	@Override
	public void removeObserver(IObserver o) {
		observers.remove(o);
		observerSize--;
	}
	
}
